#qpy:pygame
from math import sin, cos, floor
import sys
f = open('log.py', 'w')
sys.stdout = f
sys.stderr = f


import pygame

def rc(x, y):
  a = sin(x * 1.1 + y * 102.3) * 10
  r = a - floor(a)
  a = sin(x * 1.3 + y * 102.7) * 10
  g = a - floor(a)
  a = sin(x * 1.5 + y * 103.1) * 10
  b = a - floor(a)
  return (int(r*255), int(g*255), int(b*255))
  
dx = 0
dy = 0


pygame.init()
screen = pygame.display.set_mode((50, 50))
clock = pygame.time.Clock()
while True:
  clock.tick(90)
  for e in pygame.event.get():
    #print(e)
    if e.type == pygame.MOUSEMOTION:
      if e.buttons == (1, 0, 0):
        x, y = e.rel
        dx += -x
        dy += -y
  
  
  screen.fill((0, 0, 0))
  for x_ in range(-100, 1201, 100):
    for y_ in range(-100, 2501, 100):
      x = x_ - dx % 100
      y = y_ - dy % 100
      pygame.draw.rect(screen, rc((x_ +dx) / 100, (y_ + dy) / 100),
      	  (x, y, 80, 80))
  
  pygame.display.update()